"""
Case Type   : 系统视图
Case Name   : 测试新增系统视图，identity_columns字段与数据类型
Create At   : 2025-11-18
Owner       : lvlintao666
Description :
    1.查看系统视图identity_columns的结构
    2.该视图字段与对应字段数据类型是否正确
Expect      :
    1.查看系统视图identity_columns的结构成功
    2.该视图字段与字段数据类型对应正确
History     :
"""

import sys
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH

logger = Logger()

class IndexIdentityColumns(unittest.TestCase):
    def setUp(self):
        logger.info('----------------this is setup-----------------------')
        logger.info('--------------OpenGauss_Compatibility_D_View_IdentityColumns_Case0001开始执行--------------')
        self.com = Common()
        self.comsh = CommonSH('PrimaryDbDmode')
        self.expect_result_dict = {
            'Column': ['object_id', 'name', 'column_id', 'system_type_id', 'user_type_id',
                       'max_length', 'precision', 'scale', 'collation_name', 'is_nullable',
                       'is_ansi_padded', 'is_rowguidcol', 'is_identity', 'is_computed',
                       'is_filestream', 'is_replicated',
                       'is_non_sql_subscribed', 'is_merge_published', 'is_dts_replicated',
                       'is_xml_document', 'xml_collection_id', 'default_object_id', 'rule_object_id',
                       'is_sparse', 'is_column_set', 'generated_always_type', 'generated_always_type_desc',
                       'encryption_type', 'encryption_type_desc', 'encryption_algorithm_name',
                       'column_encryption_key_id', 'column_encryption_key_database_name',
                       'is_hidden', 'is_masked', 'graph_type', 'graph_type_desc', 'seed_value',
                       'increment_value', 'last_value', 'is_not_for_replication'],
            'Type': ['oid', 'name', 'integer', 'oid', 'oid', 'smallint', 'smallint', 'smallint', 'name',
                     'bit(1)', 'bit(1)', 'bit(1)', 'bit(1)', 'bit(1)', 'bit(1)', '\"bit\"', 'bit(1)', 'bit(1)',
                     'bit(1)', 'bit(1)', 'oid', 'oid', 'integer', 'bit(1)', 'bit(1)', 'tinyint',
                     'nvarchar2(60)', 'integer', 'nvarchar2(64)', 'name', 'oid', 'name', 'bit(1)',
                     'bit(1)', 'integer', 'nvarchar2(60)', 'sql_variant', 'sql_variant', 'sql_variant', 'bit(1)']}

    def test_Index_Identity_Columns(self):
        logger.info('----------------------------查看表结构-----------------------------')
        msg = self.comsh.execut_db_sql('\d identity_columns')
        logger.info(msg)
        result_dict = self.com.format_sql_result(msg)
        logger.info(result_dict)
        del result_dict['Modifiers']
        self.maxDiff = None
        self.assertDictEqual(self.expect_result_dict, result_dict)

    def tearDown(self):
        logger.info('----------------this is tearDown-----------------------')
        # 无须清理环境
        logger.info('-----------------------OpenGauss_Compatibility_D_View_IdentityColumns_Case0001执行完成-----------------------------')

